package com.medical.goods.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;

import com.medical.goods.entity.vo.SeckillVo;
import com.medical.goods.service.CommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.medical.goods.entity.SeckillEntity;
import com.medical.goods.service.SeckillService;
import com.medical.common.utils.PageUtils;
import com.medical.common.utils.R;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2021-08-13 20:42:37
 */
@RestController
@RequestMapping("goods/seckill")
public class SeckillController {
    @Autowired
    private SeckillService seckillService;

    @Autowired
    private CommodityService commodityService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = seckillService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		SeckillEntity seckill = seckillService.getById(id);

        return R.ok().put("seckill", seckill);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SeckillEntity seckill){
		seckillService.save(seckill);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SeckillEntity seckill){
		seckillService.updateById(seckill);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		seckillService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 批量添加商品到秒杀表
     * 通过获取商品id赋值到秒杀表的gid
     * 通过商品id获取到商品信息赋值到秒杀表商品信息
     */
    @RequestMapping("/add")  //ids为商品的ids
    public R add(@RequestBody Integer[] ids){
        seckillService.selectByIds(ids);
        return R.ok();
    }

    /**
     * 批量修改秒杀商品信息
     */
    @RequestMapping("/amend")  //ids为秒杀商品的ids
    public R amend(@RequestBody ArrayList<SeckillVo> seckillVos){
        seckillService.amend(seckillVos);
        return R.ok();
    }



}
